import { ERROR_CODE, MSG, SUCCESS_CODE } from "../../constants";
import { checkUser } from "./utils";


const login = {
  method: "post",
  url: "/auth/login",
  cb: (req: any) => {
    const { username, password } = req.body
    const { token, userInfo, valid, tokenKey } = checkUser({ username, password })    
    if (valid) {
      // const roleRouters = generateRoleRouter(userInfo?.id)
      return {
        code: SUCCESS_CODE,
        data: {
          token,
          tokenKey,
          userInfo,
          // roleRouters,
        },
        msg: MSG.SUCCESS,
      }
    } else {
      return {
        code: ERROR_CODE,
        msg: "账号或密码错误",
        success: false
      }
    }
  }
}


export const loginMock = [login]